﻿using AutoMapper;
using Hotel.Common;
using Hotel.Domain;
using Hotel.IRepository;
using Hotel.IServices;
using Hotel.IServices.RequestDTO;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hotel.Services
{
    public class AddGoodsTypes: IAddGoodsTypes
    {
        private readonly IBaseRepository<GoogdsType> goodsTypes;
        private readonly ILogger<AddUserServuces> logger;
        private readonly IMapper mapper;

        public AddGoodsTypes(IBaseRepository<GoogdsType> goodsTypes, ILogger<AddUserServuces> logger, IMapper mapper)
        {
            this.goodsTypes = goodsTypes;
            this.logger = logger;
            this.mapper = mapper;
        }

        /// <summary>
        /// 添加商品类型
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public  async  Task<ApiResult> AddGoodsType(AddGoodsTypeDto dto)
        {
            var result = new ApiResult("添加失败");
      var data    = mapper.Map<GoogdsType>(dto);
       var res=     await goodsTypes.InsertDataAsync(data);
            if(res)
            {
                result.Success();
            }
            return result;
        }
    }
}
